﻿Imports Microsoft.Practices.Composite.Modularity
Imports Microsoft.Practices.Composite.Regions
Imports EHaskins.Frc.Dashboard
Imports Microsoft.Practices.Unity
Imports EHaskins.Frc.Infrastructure

Public Class OiModule
    Implements IModule
    Dim _container As IUnityContainer

    Dim _regionManager As IRegionManager
    Dim _dashboard As IDashboardController
    ''' <summary>
    ''' Initializes a new instance of the OiModule class.
    ''' </summary>
    ''' <param name="container"></param>
    ''' <param name="regionManager"></param>
    ''' <param name="dashboard"></param>
    Public Sub New(ByVal container As IUnityContainer, ByVal regionManager As IRegionManager, ByVal dashboard As IDashboardController)
        _container = container
        _regionManager = regionManager
        _dashboard = dashboard
    End Sub

    Public Sub Initialize() Implements Microsoft.Practices.Composite.Modularity.IModule.Initialize
        Try
            RegisterViewsAndServices()
            _dashboard.Processors.Add(_container.Resolve(Of IOiDataProcessor)())
            '_dashboard.Processors.Add(New OiDataProcessor())

            Dim viewModel = _container.Resolve(Of IOIModuleViewModel)()
            Dim region = _regionManager.Regions(Regions.MainContent)
            region.Add(viewModel.View)
            region.Activate(viewModel.View)
        Catch ex As Exception
            Throw
        End Try
    End Sub
    Private Sub RegisterViewsAndServices()
        _container.RegisterType(Of OIDashboardView, OIDashboardView)()
        _container.RegisterType(Of IOIModuleViewModel, OIModuleViewModel)()
        _container.RegisterType(Of IOiDataProcessor, OiDataProcessor)(New ContainerControlledLifetimeManager())
    End Sub
End Class
